#!/bin/bash

PID="PID"

if [ ! $# == 1 ];
then
  echo "USAGE:$0 start|stop|restart"
  exit
fi


case $1 in
start)
   echo start

   if [ -f "$PID" ]
   then
   echo "Code is runing,yor need stop current"
   exit
   fi

    rm -f log
   ./Console.php&

   if [ $? == 0 ]
   then
    echo $! > PID
   else
    echo "Code Run Faild!"
    exit
   fi

   ;;
stop)
   echo stop

   if [ ! -f $PID ]
   then
   echo "no code Runing!"
   exit
   fi

   _PID=$(cat PID)

   kill -15 $_PID
   rm $PID

   ;;
restart)
   echo restart
   ;;
*)
   echo "USAGE:$0 start|stop|restart"
   ;;
esac